package com.woniuxy.microuserserver.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.microcommonserver.bean.user_hpd.UserAddress;
import com.woniuxy.microcommonserver.pageHelper.PageRequest;
import com.woniuxy.microuserserver.mapper.UserAddressMapper;
import com.woniuxy.microuserserver.service.IUserAddressService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Transactional(readOnly = true)
@Service
public class UserAddressServiceImpl implements IUserAddressService {
    @Resource
    private UserAddressMapper userAddressMapper;

    @Override
    public List<UserAddress> findAll() {
        return userAddressMapper.findAll();
    }

    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
    @Override
    public void addNewAddress(UserAddress userAddress) {
            userAddressMapper.addNewAddress(userAddress);
    }

    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
    @Override
    public void updateAddress(UserAddress userAddress) {
        userAddressMapper.updateAddress(userAddress);
    }

    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
    @Override
    public void deleteAddress(Long id) {
        userAddressMapper.deleteAddress(id);
    }

    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
    @Override
    public void setDefaultAddress(Long id) {
        userAddressMapper.setDefaultAddress(id);
    }

    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
    @Override
    public void setNotDefaultAll(UserAddress userAddress) {
        userAddressMapper.setNotDefaultAll(userAddress);
    }


    @Override
    public Integer countByUid(UserAddress userAddress) {
        return userAddressMapper.countByUid(userAddress);
    }

    @Override
    public UserAddress findById(Long id) {
        return userAddressMapper.findById(id);
    }
}
